<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta content="yes" name="apple-mobile-web-app-capable">
    <meta content="yes" name="apple-touch-fullscreen">
    <meta content="telephone=no,email=no" name="format-detection">
    <meta name="viewport"
        content="initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no,width=device-width, viewport-fit=cover">
    <title>六力学校</title>
    <link rel="stylesheet" href="./css/reset.css">
    <link rel="stylesheet" href="./css/public.css">
    <link rel="stylesheet" href="./css/index.css">
</head>

<body>
    <div class="pub_header">
        <div class="nav">
            <div class="logo">
                <a href="https://www.liulixuexiao.com">
                    <img src="./image/logo.png" alt="">
                </a>
            </div>
            <!--  -->
            <div class="nav_list nologin">
                <a href="javascript:;">
                    <div class="nav_item" onclick="onShow(true)">
                        <img src="./image/img1.png" alt="">
                        <p>登录</p>
                    </div>
                </a>
                <a href="javascript:;" onclick="onShow(false)">
                    <div class="nav_item">
                        <p>注册</p>
                    </div>
                </a>
            </div>
            <!--  -->
            <div class="nav_list logout">
                <a href="javascript:;">
                    <div class="nav_item">
                        <img src="./image/img1.png" alt="">
                        <p class="logout_phone"></p>
                    </div>
                </a>
                <a href="javascript:;" onclick="logout()">
                    <div class="nav_item">
                        <p>退出登陆</p>
                    </div>
                </a>
            </div>
        </div>
    </div>
    <div class="pub_contain">
        <div class="banner">
            <img src="" alt="">
        </div>
        <!--  -->
        <div class="text"></div>
        <!--  -->
        <div class="apply">
            <div class="apply_title">报名申请</div>
            <div class="table">
                <div class="table_title">
                    <div>项目名称</div>
                    <div>学位预定年级</div>
                    <div>学位预定校区</div>
                    <div>操作</div>
                </div>
                <div class="table_cont"></div>
                <div class="nodata">暂无项目信息</div>
            </div>
        </div>
        <!-- 注册 -->
        <div class="popup sign">
            <div class="popup_cont">
                <img class="popup_close" src="./image/close.png" alt="">
                <div class="popup_title">请注册</div>
                <div class="popup_item">
                    <img src="./image/img3.png" alt="">
                    <div>
                        <input type="text" id="sign_number" placeholder="请输入手机号">
                    </div>
                </div>
                <div class="popup_item">
                    <img src="./image/img4.png" alt="">
                    <div>
                        <input type="text" id="sign_code" placeholder="请输入短信验证码">
                    </div>
                    <div class="popup_send" onclick="onSend()">获取验证码</div>
                </div>
                <div class="popup_login" onclick="onLogin()">注册</div>
                <div class="popup_sign">已有账号？请<span onclick="onShow(true)">登录</span></div>
            </div>
        </div>
        <!-- 登录 -->
        <div class="popup login">
            <div class="popup_cont">
                <img class="popup_close" src="./image/close.png" alt="">
                <div class="popup_title">欢迎登录</div>
                <div class="popup_item">
                    <img src="./image/img3.png" alt="">
                    <div>
                        <input type="text" id="login_number" placeholder="请输入手机号">
                    </div>
                </div>
                <div class="popup_item">
                    <img src="./image/img4.png" alt="">
                    <div>
                        <input type="text" id="login_code" placeholder="请输入短信验证码">
                    </div>
                    <div class="popup_send" onclick="onSend()">获取验证码</div>
                </div>
                <div class="popup_login" onclick="onLogin()">登录</div>
                <div class="popup_sign"><span onclick="onShow(false)">注册</span></div>
            </div>
        </div>
        <!-- 协议 -->
        <div class="popup treaty">
            <div class="popup_cont">
                <img class="popup_close" src="./image/close.png" alt="">
                <div class="popup_title"></div>
                <div class="popup_html"></div>
                <div class="popup_radio">
                    <div class="radio on"></div> 我已阅读以上内容，并且同意
                </div>
                <div class="popup_login next">下一步</div>
            </div>
        </div>
    </div>
    <div class="pub_footer">
        <p>Copyright © 2005-2013天津武清六力学校 <a href="#">津ICP备19012091号-1</a></p>
        <p>天津六力教育是一家专业的北京、天津私立国际学校（包含小学、初中、高中、天津A-Level课程等），如果您家孩子有这方面需求，欢迎咨询：天津私立学校的客服，期待您的来电</p>
    </div>
</body>
<script src="./js/jquery-2.0.3.min.js"></script>
<script src="./js/message.js"></script>
<script src="./js/public.js"></script>
<script>
    let url = '' // 登录 注册接口名
    let status = true // true登录 false注册 - 状态
    let num = 60 // 倒计时时间
    let radio = true
    let id = ''


    // 首页信息
    $.ajax({
        url: ajaxUrl + '/Index/enroll',
        type: "POST",
        dataType: "json",
        success: function (data) {
            if (data.status == 1) {
                $(".banner").find('img').attr('src', 'http://bmsystem.liulixuexiao.com' + data.info.banner)
                $(".text").html(data.info.content)
            }
        }
    })

    // 列表
    $.ajax({
        url: ajaxUrl + '/Index/enrollList',
        type: "POST",
        dataType: "json",
        success: function (data) {
            if (data.status == 1) {
                if (data.info.length) {
                    $('.nodata').hide()
                    for (var i = 0; i < data.info.length; i++) {
                        let html = `<div class="table_item">
                        <div>${data.info[i].title}</div>
                        <div>${data.info[i].grade}</div>
                        <div>${data.info[i].campus}</div>
                        <div>
                            <button class="subscribe" attr-id=${data.info[i].id}>预约</button>
                        </div>
                    </div>`

                        $('.table_cont').append(html)
                    }
                }
            }
        }
    })

    // 协议内容
    $.ajax({
        url: ajaxUrl + '/Index/Agreement',
        type: "POST",
        dataType: "json",
        success: function (data) {
            if (data.status == 1) {
                $('.popup_html').html(data.info.content)
                $('.popup_title').html(data.info.title)
            }
        }
    })

    // 浮层
    $(document).on('click', '.popup_close', function () {
        $('.popup').hide()
    })

    // 登录注册切换
    function onShow(type) {
        if (type) {
            $('.login').show()
            $('.sign').hide()
            $('.treaty').hide()
            url = '/Index/login'
            status = true
        } else {
            $('.login').hide()
            $('.sign').show()
            $('.treaty').hide()
            url = '/Index/register'
            status = false
        }
    }

    // 发送验证码
    function onSend() {
        let params = {
            value: 1,
            numberback: status ? $('#login_number').val() : $('#sign_number').val()
        }
        if (!params.numberback) {
            alert('请输入手机号码')
            return true
        } else if (!/^1[3456789][0-9]{9}$/.test(params.numberback)) {
            alert('手机号码格式有误')
            return true
        }
        $.ajax({
            url: ajaxUrl + url,
            type: "POST",
            data: params,
            dataType: "json",
            success: function (data) {
                if (data.status == 1) {
                    sendTime()
                }
                alert(data.info)
            }
        })
    }

    // 验证码倒计时
    function sendTime() {
        $('.popup_send').attr('onclick', null)
        var time = setInterval(function () {
            num--
            $('.popup_send').html('获取验证码 ' + num)
            if (num <= 0) {
                clearInterval(time)
                $('.popup_send').html('获取验证码')
                $('.popup_send').attr('onclick', 'onSend()')
                num = 60
                return false
            }
        }, 1000)
    }

    // 登录
    function onLogin() {
        let params = {
            numberback: status ? $('#login_number').val() : $('#sign_number').val(),
            exnum: status ? $('#login_code').val() : $('#sign_code').val(),
        }
        $.ajax({
            url: ajaxUrl + url,
            type: "POST",
            data: params,
            dataType: "json",
            success: function (data) {
                if (data.status == 1) {
                    localStorage.setItem('token', data.sign)
                    localStorage.setItem('uid', data.uid)

                    localStorage.setItem('phone', params.numberback)
                    $(".popup").hide()
                    isLogin()
                } else {
                    alert(data.info)
                }
            }
        })
    }

    // 协议
    function isToken() {
        let token = localStorage.getItem('token')
        if (token == null || !token) {
            onShow(true)
            return false
        } else {
            return true
        }
    }

    $(document).on('click', '.subscribe', function () {
        $(".treaty").show()
        id = $(this).attr('attr-id')
    })

    // 判断登录状态
    $(document).on('click', '.next', function () {
        if (!$('.radio').hasClass('on')) {
            alert('请勾选协议内容')
            return false
        }
        if (isToken()) {
            window.location.href = './form.html?id=' + id
        }
    })

    // 协议选中
    $('.radio').on('click', function () {
        $(this).toggleClass("on")
        radio = !radio
    })
</script>

</html>